//
//  RHMineViewController.m
//  RuiHeAppApp
//
//  Created by Yan Chen on 2023/7/5.
//

#import "RHMineViewController.h"
#import "RHEditInforViewController.h"
#import "RHMyApplicationController.h"
#import "RHMyApprovalController.h"

#import "RHSetViewController.h"
#import "RHAccountViewController.h"
#import "RHMineViewCell.h"
#import "RHCountryRegionVC.h"
#import "RHNetworkOptionVC.h"
#import "RHMyRepairsController.h"
#import "RHMQTTTestController.h"
#import "RHUserModel.h"
#import "RHMeUserListVC.h"
#import "RHBrandIDVC.h"
#import "RHNavigationController.h"
#import "RHLoginViewController.h"
#import "RHTools.h"
#import "RHMyQRCodeVC.h"
#import "RHBaseWebViewController.h"
#import "RHAboutViewController.h"
#import "RHLanguageSettingVC.h"
#import "RHTestVC.h"
#import "RHLocalBleDeviceVC.h"
#import "RHGolbalServerModel.h"
#import "EnvironmentManage.h"
#import "NetworkConfig.h"
#import "KWTProduceManageVC.h"
#import "KWTPolicyListVC.h"
#import "RHDeviceReportVC.h"


@interface RHMineViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic ,strong) UIView *headBgView;

@property (nonatomic ,strong) UIView *headerView;

@property (nonatomic ,strong) UIView *footBgView;

@property (nonatomic ,strong) UIImageView *headV;

@property (nonatomic ,strong) UIImageView *qrCodeImg;

@property (nonatomic ,strong) QMUILabel *nickNameLab;

@property (nonatomic ,strong) QMUILabel *roleLab;

@property (nonatomic ,strong) UITableView *tableView;

@property (nonatomic ,strong) UIView *customNav;

@property (nonatomic ,strong) NSMutableArray *dataArr;
@end

@implementation RHMineViewController

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear: animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupUI];
    [self getAccountInfo];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(getAccountInfo) name:@"AccountInfoUpdateNO" object:nil];
    
//    @{CellTitle:@"我的申请".rh_localized,CellIcon:@"mine_icon_03",CellAction:@"myApplidation"},
//    @{CellTitle:@"我的审核".rh_localized,CellIcon:@"mine_icon_04",CellAction:@"myApproval"},
    
    NSString *areaCode = [UserDefaults objectForKey:kAreacode];
    NSString *country = [RHTools getAreaNameWithAreaCode:areaCode];
    NSString *lan = [kUserDefaults objectForKey:kLanguage];
    if([lan containsString:@"zh"]){
        lan = @"中文";
    }else if ([lan containsString:@"en"]){//英语
        lan = @"English";
    }else if ([lan containsString:@"es"]){//西班牙语
        lan = @"Español";
    }
    else if ([lan containsString:@"fr"]){//法语
        lan = @"Français";
    }
    else if ([lan containsString:@"pl"]){//波兰语
        lan = @"Polski";
    }
    else if ([lan containsString:@"de"]){//德语
        lan = @"Deutsch";
    }
    else if ([lan containsString:@"ja"]){//日语
        lan = @"日本語";
    }
    else if ([lan containsString:@"it"]){//意大利语
        lan = @"Italiano";
    }
    else{
        lan = @"";
    }
    NSString *version = [[[NSBundle mainBundle]infoDictionary] objectForKey:@"CFBundleShortVersionString"];
    
    //终端用户以上的管理层
    self.dataArr = [NSMutableArray arrayWithArray:@[
        @[
            @{
                CellTitle:@"用户管理".rh_localized,
                CellIcon:@"kwt_mine_user_manage",
                CellAction:@"userManage"
            },
            @{
                CellTitle:@"设备报表".rh_localized,
                CellIcon:@"kwt_mine_device_repord",
                CellAction:@"deviceRepord"
            },
            @{
                CellTitle:@"策略下发记录".rh_localized,
                CellIcon:@"kwt_mine_policy_record",
                CellAction:@"policyRecord"
            },
            @{
                CellTitle:@"维修记录".rh_localized,
                CellIcon:@"kwt_mine_repair_record",
                CellAction:@"myRepair"
            }
         ].mutableCopy,
        @[
            @{
                CellTitle:@"语言".rh_localized,
                CellIcon:@"kwt_mine_language",
                CellAction:@"myLanguage",
                CellContent:lan
            },
            @{
                CellTitle:@"配网".rh_localized,
                CellIcon:@"kwt_mine_network",
                CellAction:@"networkConfig"
            },
            @{
                CellTitle:@"本地监控".rh_localized,
                CellIcon:@"kwt_mine_local_monitor",
                CellAction:@"localMonitorAction"
            }
         ].mutableCopy,
        @[
            @{
                CellTitle:@"服务条款".rh_localized,
                CellIcon:@"kwt_mine_service_terms",
                CellAction:@"serviceTerms"},
            @{
                CellTitle:@"隐私政策".rh_localized,
                CellIcon:@"kwt_mine_privacy_policy",
                CellAction:@"privacyPolicy"
            },
            @{
                CellTitle:@"关于我们".rh_localized,
                CellIcon:@"kwt_mine_about_us",
                CellAction:@"aboutUs",
                CellContent:version
            }
         ].mutableCopy
       ]
  ];
    //品牌商才能切换区域
    if([PrivateMange share].currentUser.hierarchyCode == UserRoleTypeBrandMerchants){
        self.dataArr = [NSMutableArray arrayWithArray:@[
            @[
                @{
                    CellTitle:@"用户管理".rh_localized,
                    CellIcon:@"kwt_mine_user_manage",
                    CellAction:@"userManage"
                },
                @{
                    CellTitle:@"设备报表".rh_localized,
                    CellIcon:@"kwt_mine_device_repord",
                    CellAction:@"deviceRepord"
                },
                @{
                    CellTitle:@"策略下发记录".rh_localized,
                    CellIcon:@"kwt_mine_policy_record",
                    CellAction:@"policyRecord"
                }
             ].mutableCopy,
            @[
              @{
                CellTitle:@"语言".rh_localized,
                CellIcon:@"kwt_mine_language",
                CellAction:@"myLanguage",
                CellContent:lan
              },
              @{
                CellTitle:@"区域选择".rh_localized,
                CellIcon:@"mine_region",
                CellAction:@"changeRegion",
                CellContent:country
              },
              @{
                CellTitle:@"配网".rh_localized,
                CellIcon:@"kwt_mine_network",
                CellAction:@"networkConfig"
              }
            ].mutableCopy,
            @[
              @{
                CellTitle:@"服务条款".rh_localized,
                CellIcon:@"kwt_mine_service_terms",
                CellAction:@"serviceTerms"
              },
              @{
                CellTitle:@"隐私政策".rh_localized,
                CellIcon:@"kwt_mine_privacy_policy",
                CellAction:@"privacyPolicy"
              },
              @{CellTitle:@"关于我们".rh_localized,
                CellIcon:@"kwt_mine_about_us",
                CellAction:@"aboutUs",
                CellContent:version
              }
            ].mutableCopy
           ]
      ];
        
        
        [self updateRegionName];

    }
    

    //终端用户本地监控
    if([PrivateMange share].currentUser.orgType == OrganizationTypeUser){

        self.dataArr = [NSMutableArray arrayWithArray:@[
            @[
                @{
                    CellTitle:@"设备报表".rh_localized,
                    CellIcon:@"kwt_mine_device_repord",
                    CellAction:@"deviceRepord"
                },
                @{
                    CellTitle:@"策略下发记录".rh_localized,
                    CellIcon:@"kwt_mine_policy_record",
                    CellAction:@"policyRecord"
                },
                @{
                    CellTitle:@"维修记录".rh_localized,
                    CellIcon:@"kwt_mine_repair_record",
                    CellAction:@"myRepair"
                }
             ].mutableCopy,
            @[
                @{
                    CellTitle:@"语言".rh_localized,
                    CellIcon:@"kwt_mine_language",
                    CellAction:@"myLanguage",
                    CellContent:lan
                },
                @{
                    CellTitle:@"配网".rh_localized,
                    CellIcon:@"kwt_mine_network",
                    CellAction:@"networkConfig"
                },
                @{
                    CellTitle:@"本地监控".rh_localized,
                    CellIcon:@"kwt_mine_local_monitor",
                    CellAction:@"localMonitorAction"
                }
             ].mutableCopy,
            @[
                @{
                    CellTitle:@"服务条款".rh_localized,
                    CellIcon:@"kwt_mine_service_terms",
                    CellAction:@"serviceTerms"},
                @{
                    CellTitle:@"隐私政策".rh_localized,
                    CellIcon:@"kwt_mine_privacy_policy",
                    CellAction:@"privacyPolicy"
                },
                @{
                    CellTitle:@"关于我们".rh_localized,
                    CellIcon:@"kwt_mine_about_us",
                    CellAction:@"aboutUs",
                    CellContent:version
                }
             ].mutableCopy
           ]
      ];
    }
    
    if (Project_Test) {
        [self.dataArr addObject:@[@{CellTitle:@"MQTT TEST",CellIcon:@"mine_icon_08",CellAction:@"mqttTest"},
                                            @{CellTitle:@"chart TEST",CellIcon:@"mine_icon_08",CellAction:@"chartTest"}]];
        
    }

    
    [self qrCodeStatus];
}

#pragma mark ------ 获取个人信息 --------
-(void)getAccountInfo
{
    kWeakSelf;
    [QMUITips showLoadingInView:self.view];
    [[PrivateMange share]getUserInfoSuccess:^(RHUserModel * _Nonnull userModel) {
        weakSelf.nickNameLab.text = ValidNullDataToString(userModel.nickName, userModel.userName);
      
//        NSString *country = [RHTools getRegionNameWithCode:userModel.countryCode];
        NSString *country = [UserDefaults objectForKey:kCountry];
        NSString *role =  [RHTools getRoleContentWithType:userModel.orgType brandId:userModel.brandId];
        weakSelf.roleLab.text = country.length>0?[NSString stringWithFormat:@"%@",role]:role;
        [weakSelf.headV sd_setImageWithURL:[NSURL URLWithString:userModel.avatar] placeholderImage:[UIImage imageNamed:@"kwt_avatar_default"]];
        [weakSelf.tableView endHeaderRefresh];
        
        [weakSelf qrCodeStatus];
        if ([PrivateMange share].currentUser.hierarchyCode<UserRoleTypeTerminalUser) {
//            weakSelf.roleLab.text = nil;
        }
    }];
        
}
#pragma mark ------- 是否显示二维码 -------
-(void)qrCodeStatus
{
    //是否显示二维码  (品牌商和普通用户不展示)
    BOOL isShowQRCode = [PrivateMange share].currentUser.orgType == OrganizationTypeOperation ||
    [PrivateMange share].currentUser.orgType == OrganizationTypeInstaller||
    ([PrivateMange share].currentUser.orgType == OrganizationTypeUser && [PrivateMange share].currentUser.brandId == brand_id.integerValue);
    [self headerView];
//    self.qrCodeImg.hidden = !isShowQRCode;
    self.qrCodeImg.hidden = YES;//隐藏掉
}

- (void)setupUI{
   
    [self.view setBackgroundColor:CFTabViewBgColor];
    UIView *bgView = kView;
    [bgView setBackgroundColor:CFTabViewBgColor];
    [self.view addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_offset(0);
        make.bottom.mas_offset(0);
    }];
    
    UIImageView *imageV = [[UIImageView alloc] init];
    [imageV setImage:[UIImage imageNamed:@"kwt_mine_bg"]];
    [self.view addSubview:imageV];
    [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_offset(0);
        make.top.mas_offset(0);
        make.height.mas_equalTo(imageV.mas_width).multipliedBy(215/420.0);
    }];
    
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    [_tableView setBackgroundColor:UIColor.clearColor];
    [_tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    [_tableView setDelegate:self];
    [_tableView setDataSource:self];
    [_tableView registerClass:[RHMineViewCell class] forCellReuseIdentifier:@"RHMineViewCell"];
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    _tableView.tableHeaderView = self.headBgView;
    [self.view addSubview:_tableView];
    if (@available(iOS 11.0, *)) {
        _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }

    if (@available(iOS 15.0, *)) {
        _tableView.sectionHeaderTopPadding = 0;
    }
    kWeakSelf;
    [self.tableView addHeaderRefresh:^{
        [weakSelf getAccountInfo];
        [weakSelf updateRegionName];

    }];
    
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(0, 0, 20, 0));
    }];
    
    _customNav = [[UIView alloc] init];
    [_customNav setBackgroundColor:UIColor.clearColor];
    [self.view addSubview:_customNav];

    
    QMUIButton *btn = [QMUIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:@"kwt_mine_set_white"] forState:UIControlStateNormal];
    [btn setImagePosition:QMUIButtonImagePositionRight];
    [btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight];
    [_customNav addSubview:btn];
    
    
    [_customNav mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, kNavBarHeight+kStatusBarHeight));
        make.left.top.mas_offset(0);
    }];
    
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(100, kNavBarHeight));
        make.right.mas_offset(-15);
        make.top.mas_offset(kStatusBarHeight);
    }];
    
    [[btn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        RHAccountViewController *vc = [[RHAccountViewController alloc] init];
        [weakSelf.navigationController pushViewController:vc animated:YES];
    }];
}


- (UIView *)headBgView{
    
    if(!_headBgView){
        _headBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kUI_WINDOW_W, 140+kSafe_top+10)];

        UITapGestureRecognizer *tapView = [[UITapGestureRecognizer alloc] init];
        _headBgView.userInteractionEnabled = YES;
        [_headBgView addGestureRecognizer:tapView];
        kWeakSelf;
        [tapView.rac_gestureSignal subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
            NSLog(@"=----");
            RHEditInforViewController *vc = [[RHEditInforViewController alloc] init];
            [weakSelf.navigationController pushViewController:vc animated:YES];
        }];
        
        _headV = [[UIImageView alloc] init];
        [_headV setImage:[UIImage imageNamed:@"kwt_avatar_default"]];
        _headV.contentMode = UIViewContentModeScaleAspectFill;
        [_headV.layer setCornerRadius:34];
        _headV.layer.masksToBounds = YES;
        [_headV setBackgroundColor:UIColor.clearColor];
        [_headBgView addSubview:_headV];
        
        
        UIView *nameView = kView;
        [_headBgView addSubview:nameView];
        
        _nickNameLab = [[QMUILabel alloc] init];
        [_nickNameLab setTextAlignment:NSTextAlignmentLeft];
        [_nickNameLab setFont:[UIFont boldSystemFontOfSize:16]];
        [_nickNameLab setTextColor:kCOLOR_HEX(@"FFFFFF")];
        _nickNameLab.numberOfLines = 2;
        [nameView addSubview:_nickNameLab];
        
        _roleLab = [[QMUILabel alloc] init];
        [_roleLab setTextAlignment:NSTextAlignmentLeft];
        [_roleLab setFont:[UIFont systemFontOfSize:12]];
        [_roleLab setTextColor:[kCOLOR_HEX(@"FFFFFF") colorWithAlphaComponent:0.95]];
        [nameView addSubview:_roleLab];
        
        UIImageView *arrowView = [[UIImageView alloc] init];
        [arrowView setImage:[UIImage imageNamed:@"kwt_home_arrow_white"]];
        [_headBgView addSubview:arrowView];
        
        _qrCodeImg = [[UIImageView alloc] init];
        [_qrCodeImg setImage:[UIImage imageNamed:@"kwt_mine_qr_code_white"]];
        [_headBgView addSubview:_qrCodeImg];
        _qrCodeImg.hidden = YES;
        
        UIView *itemBgView = kView;
        itemBgView.backgroundColor = [UIColor clearColor];
        itemBgView.layer.cornerRadius = 8;
        itemBgView.layer.masksToBounds = YES;
        [_headBgView addSubview:itemBgView];
        
        [itemBgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_offset(15);
            make.right.mas_offset(-15);
            make.bottom.mas_offset(-15);
            make.height.offset(100);
        }];
        

        [_headV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(68, 68));
            make.left.mas_offset(15);
            make.top.mas_offset(kSafe_top+30);
        }];
        
        [nameView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.headV.mas_right).offset(10);
            make.right.equalTo(weakSelf.qrCodeImg.mas_left).offset(-3);
            make.centerY.equalTo(weakSelf.headV);
        }];
        [_nickNameLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.right.mas_offset(0);
        }];
        
        [_roleLab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.mas_offset(0);
            make.top.equalTo(weakSelf.nickNameLab.mas_bottom).offset(5);
        }];
        
        [arrowView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(20, 20));
            make.centerY.equalTo(weakSelf.headV);
            make.right.mas_offset(-18);
        }];
        
        [_qrCodeImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(20, 20));
            make.centerY.equalTo(arrowView);
            make.right.equalTo(arrowView.mas_left).offset(-10);
        }];
        
        [_nickNameLab setText:@"--"];
        [_roleLab setText:@""];
        
    }
    
    
    return _headBgView;
}

- (UIView *)footBgView{
    if(!_footBgView){
        _footBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH,200)];
        [_footBgView setBackgroundColor:UIColor.clearColor];
        
        UIView *view =  [[UIView alloc] initWithFrame:CGRectMake(15, 0, SCREEN_WIDTH-30,200)];
        [view setBackgroundColor:UIColor.whiteColor];
        [view round:5 RectCorners:UIRectCornerBottomLeft|UIRectCornerBottomRight];
        [_footBgView addSubview:view];
    }
    return _footBgView;
}



#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.dataArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSMutableArray *sectionArr = self.dataArr[section];
    return  sectionArr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 15;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    return nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.0;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    return nil;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    RHMineViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RHMineViewCell"];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    NSMutableArray *sectionArr = self.dataArr[indexPath.section];
    [cell setIconStr:sectionArr[indexPath.row][CellIcon]];
    [cell setTitleStr:sectionArr[indexPath.row][CellTitle]];
    [cell setContentStr:ValidNullData(sectionArr[indexPath.row][CellContent])];
    if (indexPath.row == 0) {
        cell.bgView.layer.cornerRadius = 8;
        cell.bgView.qmui_borderPosition = QMUIViewBorderPositionLeft|QMUIViewBorderPositionTop|QMUIViewBorderPositionRight;
        cell.bgView.layer.qmui_maskedCorners = QMUILayerMinXMinYCorner|QMUILayerMaxXMinYCorner;
    }else if (indexPath.row == sectionArr.count-1){
        cell.bgView.layer.cornerRadius = 8;
        cell.bgView.qmui_borderPosition = QMUIViewBorderPositionLeft|QMUIViewBorderPositionBottom|QMUIViewBorderPositionRight;
        cell.bgView.layer.qmui_maskedCorners = QMUILayerMinXMaxYCorner|QMUILayerMaxXMaxYCorner;
    }else{
        cell.bgView.layer.cornerRadius = 0;
        cell.bgView.qmui_borderPosition = QMUIViewBorderPositionLeft|QMUIViewBorderPositionRight;
        
    }
    if (sectionArr.count == 1) {
        cell.bgView.layer.cornerRadius = 8;
        cell.bgView.qmui_borderPosition = QMUIViewBorderPositionLeft|QMUIViewBorderPositionRight|QMUIViewBorderPositionTop|QMUIViewBorderPositionBottom;
    }
    [cell hideLine:(indexPath.row == sectionArr.count- 1)];
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSMutableArray *sectionArr = self.dataArr[indexPath.section];
    SEL selector = NSSelectorFromString(sectionArr[indexPath.row][CellAction]);
    if([self respondsToSelector:selector]){
        [self performSelector:selector];
    }
   
}



#pragma mark ---------- Action ----------
//区域选择
-(void)changeRegion
{
    RHCountryRegionVC *regionVC = [[RHCountryRegionVC alloc]init];
    kWeakSelf;
    regionVC.regionUpdateBlock = ^(NSString * _Nonnull region) {
        
        __block NSUInteger index = -1;
        __block NSMutableArray *tempArr;
        [weakSelf.dataArr enumerateObjectsUsingBlock:^(NSMutableArray  *_Nonnull sectionArr, NSUInteger idx, BOOL * _Nonnull stop) {
            [sectionArr enumerateObjectsUsingBlock:^(NSDictionary*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if([obj[CellTitle] isEqualToString:@"区域选择".rh_localized]){
                    index = idx;
                    tempArr = sectionArr;
                    *stop = YES;
                }
            }];
            
        }];
        if(index != -1){
            
            [tempArr replaceObjectAtIndex:index withObject:@{CellTitle:@"区域选择".rh_localized,CellIcon:@"mine_icon_01",CellAction:@"changeRegion",CellContent:[RHTools getAreaNameWithAreaCode:region]}];
            [weakSelf.tableView reloadData];
        }
        
        
    };
    [self.navigationController pushViewController:regionVC animated:YES];
}


#pragma mark ------- 更新国家地区的显示
-(void)updateRegionName
{
    kWeakSelf;
    //品牌商才能切换区域
    if([PrivateMange share].currentUser.hierarchyCode != UserRoleTypeBrandMerchants)return;
    [RHGolbalServerModel startWithBaseUrl:[EnvironmentManage sharedEnvirManage].getBaseAPIUrl APIKey:G_getServerList argument:@{} requestMethod:RequestMethodPOST requestSuccess:^(__kindof BaseRequest *request, ResultModel *resultModel) {
        
        if(resultModel.code == 200){
            
            NSArray *regionArr = resultModel.data;
            __block NSUInteger index = -1;
            __block NSMutableArray *tempArr;
            [weakSelf.dataArr enumerateObjectsUsingBlock:^(NSMutableArray *_Nonnull sectionArr, NSUInteger idx, BOOL * _Nonnull stop) {
                [sectionArr enumerateObjectsUsingBlock:^(NSDictionary*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    if([obj[CellTitle] isEqualToString:@"区域选择".rh_localized]){
                        index = idx;
                        tempArr = sectionArr;
                        *stop = YES;
                    }
                }];
                
            }];
            if(index != -1){
                __block NSString *regionName;
                //找出对应国家地区服务器显示出来
                [regionArr enumerateObjectsUsingBlock:^(RHGolbalServerModel*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                    if ([obj.areaCode isEqualToString:[kUserDefaults objectForKey:kAreacode]]) {
                        regionName = obj.areaName;
                    }
                }];
                
                if(regionName.length>0){
                    [tempArr replaceObjectAtIndex:index withObject:@{CellTitle:@"区域选择".rh_localized,CellIcon:@"mine_region",CellAction:@"changeRegion",CellContent:regionName}];
                    [weakSelf.tableView reloadData];
                }
                
            }
        }
    } requestFail:^(__kindof BaseRequest *request, ResultModel *resultModel) {
       
    }];
        
}

//配网
-(void)networkConfig
{
    //通用品牌不允许配网
//    if ([[NetworkConfig sharedConfig].brandID isEqualToString:@"999999999999"]) {
//        [QMUITips showError:@"品牌用户才能配网".rh_localized];
//        return;
//    }
    
    [self.navigationController pushViewController:[RHNetworkOptionVC new] animated:YES];
   
}

-(void)localMonitorAction
{
    [self.navigationController pushViewController:[RHLocalBleDeviceVC new] animated:YES];
}

//设置
-(void)systemSetting
{
    RHSetViewController *vc = [[RHSetViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

//我的二维码
-(void)myQRCode
{
    [self.navigationController pushViewController:[RHMyQRCodeVC new] animated:YES];
}

-(void)myLanguage
{
    //语言
    RHLanguageSettingVC *lanVC = [[RHLanguageSettingVC alloc]init];
    [self.navigationController pushViewController:lanVC animated:YES];
}

-(void)serviceTerms
{
    //用户协议
    RHBaseWebViewController *vc = [[RHBaseWebViewController alloc] init];
//    [vc setLocalHtml:@"terms_of_use"];
    vc.urlStr = @"https://www.ruihenergy.com/terms_of_use";
    vc.navTitle = @"服务条款".rh_localized;
    [self.navigationController pushViewController:vc animated:YES];
    
}

-(void)privacyPolicy
{
    //隐私政策
    RHBaseWebViewController *vc = [[RHBaseWebViewController alloc] init];
//    [vc setLocalHtml:@"privacy_policy"];
    vc.urlStr = @"https://www.ruihenergy.com/privacy_policy";
    vc.navTitle = @"隐私策略".rh_localized;
    [self.navigationController pushViewController:vc animated:YES];
}

//我的申请
-(void)myApplidation
{
    RHMyApplicationController *vc = [[RHMyApplicationController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

//我的审核
-(void)myApproval
{
    RHMyApprovalController *vc = [[RHMyApprovalController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)aboutUs
{
    RHAboutViewController *vc = [[RHAboutViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}


//设备报修
-(void)myRepair
{
    RHMyRepairsController *vc = [[RHMyRepairsController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

//生产管理
-(void)produceManage
{
    KWTProduceManageVC *productVC = [[KWTProduceManageVC alloc]init];
    [self.navigationController pushViewController:productVC animated:YES];
}

//策略下发记录
-(void)policyRecord
{
    KWTPolicyListVC *policyVC = [[KWTPolicyListVC alloc]init];
    [self.navigationController pushViewController:policyVC animated:YES];

}
//设备报表
-(void)deviceRepord
{
    RHDeviceReportVC *reportVC = [[RHDeviceReportVC alloc]init];
    [self.navigationController pushViewController:reportVC animated:YES];
   
}

//用户管理
-(void)userManage
{
    RHMeUserListVC *userVC = [[RHMeUserListVC alloc]init];
    [self.navigationController pushViewController:userVC animated:YES];
}


-(void)changeBrandID
{
    RHBrandIDVC *brandVC = [[RHBrandIDVC alloc]init];
    [self.navigationController pushViewController:brandVC animated:YES];
}


//MQTT测试
-(void)mqttTest
{
    RHMQTTTestController *vc = [[RHMQTTTestController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}
-(void)chartTest
{

    [self.navigationController pushViewController:[RHTestVC new] animated:YES];
}



-(void)dealloc
{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}

@end
